<?php


namespace App\Api\Service\Order\Controllers;

use App\Eloquent\Ygt\Privilege;
use Framework\BaseClass\Api\Controller;
use App\Engine\Func;
use App\Engine\OrderType;
use App\Eloquent\Ygt\DepartmentUser;

class PermissionController extends Controller
{
    /**
     * 获取工艺 分配权限
     */
    public function distributionAction(){
        $orderTypeId = request('order_type');

        $result = OrderType::getAllStepsWithDistribution($orderTypeId);

        $result->transform(function($item){
//            $item->distributionUser = Privilege::getWithDepartmentUser( $item->distribution );
            $distributionUser = DepartmentUser::getWithPrivilege($item->distribution);
            $process_id = $item->process_id;
            $distributionUser->transform(function($item) use($process_id){
                $item->process_id = $process_id;
                $item->ygtUser->avatar = $item->ygtUser->avatar ? Func::getImgUrlById($item->ygtUser->avatar) : asset('upload/appicon/logo.png');
                return $item;
            });
            $item->distributionUser = $distributionUser->toArray();
            return $item;
        });

        $result = $result->filter(function($item){
            if($item->distribution->toArray()) return true;
            return false;
        });

        return $result->values();
    }
}